8387484: [lworld] javac should warn on use of value classes#2601
8387484: [lworld] javac should warn on use of value classes#2601lahodaj wants to merge 2 commits into
Conversation
|
👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into |
|
@lahodaj This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 7 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@mcimadamore, @liach, @vicente-romero-oracle) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
| */ | ||
| public boolean declaredUsingPreviewFeature(Symbol sym) { | ||
| return false; | ||
| return sym.isValueClass(); |
There was a problem hiding this comment.
Should this include records too given how its semantics are changed? Maybe in another RFE?
There was a problem hiding this comment.
I am not completely certain, but I think this should not include records.
My understanding is that for records, only the implementation of the record's constructor changes, and that this is transparent(?) for the users of the record. I.e. the change not in the declaration/signatures, but in the implementation. If a class, e.g. PM, uses a preview feature inside an implementation only (i.e. not in a declaration), we don't taint another class, e.g. Use, that only uses PM.
For example:
$ cat PM.java
public class PM {
private boolean test(Object o) {
return o instanceof byte b;
}
}
$ cat Use.java
public class Use {
PM pm;
}
$ javac --enable-preview --source 28 -Xlint:preview PM.java Use.java
PM.java:3: warning: [preview] primitive patterns are a preview feature and may be removed in a future release.
return o instanceof byte b;
^
1 warning
There's no warning for the use of PM in Use, and Use.class is not marked a preview classfile.
Even though PM uses a preview feature (primitive patterns), it only does so inside an implementation, and so the use of the preview feature is invisible to the use site, leading to no warning.
My understanding (possibly wrong) is that the change in record constructors is similar to the use of pattern matching in the implementation of PM.
Webrevs
|
Consider source files like this:
When compiled like this:
Note that while the
TestValue.classis marked as preview, there's no warning on the use ofValueClass. This is not aligned with the JEP 12 wording:Currently javac marks the classfile preview using an explicit test in the
ClassWriter, but that does not seem quite right. This PR proposes to mark value classes asPreview.declaredUsingPreviewFeature == true, which should automatically produce a warning, and mark the appropriate classfile as preview.For the example above:
Note this will also report the warning for
Integer, when preview is enabled:Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/valhalla.git pull/2601/head:pull/2601$ git checkout pull/2601Update a local copy of the PR:
$ git checkout pull/2601$ git pull https://git.openjdk.org/valhalla.git pull/2601/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 2601View PR using the GUI difftool:
$ git pr show -t 2601Using diff file
Download this PR as a diff file:
https://git.openjdk.org/valhalla/pull/2601.diff
Using Webrev
Link to Webrev Comment